import { Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { UiService } from '../../ui.service';
import { GB } from '../../../environments/environment';
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
import { I18nService } from '../../core/i18n/i18n.service';
import { ActionSheetConfig, SkinType, ActionSheetComponent, ActionSheetService } from 'ngx-weui';
import { MessageService } from './../../core/message.service';
import { InfiniteLoaderComponent } from 'ngx-weui/infiniteloader';
import { ApiService } from 'src/app/core/api';
import { Router, ActivatedRoute } from '@angular/router';
import { StorageService } from 'src/app/core/sotrage/storage.service';

@Component({
	selector: 'app-index',
	templateUrl: './index.component.html',
	styleUrls: ['./index.component.less'],
	encapsulation: ViewEncapsulation.None,
})
export class IndexHomeComponent implements OnInit {
	@ViewChild('ios', { static: true }) iosAS: ActionSheetComponent;
	@ViewChild('android', { static: true }) androidAS: ActionSheetComponent;
	@ViewChild('auto', { static: true }) autoAS: ActionSheetComponent;
	@ViewChild(InfiniteLoaderComponent, { static: true }) il;
	restartBtn = false;

	menus: any[] = [{ text: ' English', value: 'en', other: 1 }, { text: '中文', value: 'zh' }, { text: 'わご', value: 'jp' }];
	config: ActionSheetConfig = {
		title: 'Language changes',
	} as ActionSheetConfig;

	gb = GB;
	list = [{}];
	options: any = {
		autoplay: {
			delay: 3000,
			stopOnLastSlide: false,
			disableOnInteraction: true,
		},
		observeParents: true,
		observer: true,
	};
	user: any = null;

	constructor(private i: I18nService, private api: ApiService, private sto: StorageService, private router: Router, private activeRouter:ActivatedRoute, private message: MessageService) {
		this.message.sendMessage('index');
	}
	pageData = { pageNo: 1 };
	ngOnInit() {
		this.list = this.activeRouter.snapshot.data.list;
		if(this.sto.get('user')){
			this.user = this.sto.get('user')['loginId'];
		}
		// this.uiServuce.getHomePoster()
		//   .subscribe((data: Array<server.首页海报>) => this.list = data);
	}

	

	onSel(teg) {
		switch (teg.providerType) {
			case 'AGENCY': //旅行社
				//  /travelAgency.do?travelProductId=list [index].id
				this.router.navigate(['/agency'], {
					queryParams: {
						travelProductId: teg.id,
					},
				});
				break;
			case 'GUIDE': //导游
				this.router.navigate(['/guide'], {
					queryParams: {
						travelGuideId: teg.id,
						type: '0',
					},
				});
				break;
			case 'OTHER': //其他
				this.api.get('获取对应产品的网站地址', { travelProductId: teg.id }).then(res => {
					window.open(res['url']);
				});
				break;
		}
	}
	dialogShow = false;
	onOutsize(bool) {
		this.dialogShow = bool;
	}
	chickOut() {
		this.dialogShow = false;
		this.sto.remove('user');
		this.router.navigate(['/login']);
	}
	cancel() {
		this.dialogShow = false;
	}
	gologin(){
		sessionStorage.removeItem('returnurl');
		this.router.navigateByUrl('/login');
	}
}
